package com.study.quiz.dto;

import com.study.quiz.enums.ResultMsgEnum;
import lombok.Data;

/**
 * @author CJunGod
 * @create 2020-03-09 18:51
 **/
@Data
public class ResultDTO<T> {

    private Integer code;

    private String message;

    private T data;

    public static ResultDTO indexOfMsg(ResultMsgEnum resultMsgEnum) {

        return indexOfMsg(resultMsgEnum.getCode(), resultMsgEnum.getMessage());
    }

    public static ResultDTO indexOfMsg(Integer code, String message) {
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(code);
        resultDTO.setMessage(message);

        return resultDTO;
    }

//    public static ResultDTO errorOf(QuizException e) {
//
//        return errorOf(e.getCode(), e.getMessage());
//    }

    public static ResultDTO isOk() {
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(ResultMsgEnum.SUCCESS_MESSAGE.getCode());
        resultDTO.setMessage(ResultMsgEnum.SUCCESS_MESSAGE.getMessage());

        return resultDTO;
    }

    public static <T> ResultDTO isOk(T t) {
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(ResultMsgEnum.SUCCESS_MESSAGE.getCode());
        resultDTO.setMessage(ResultMsgEnum.SUCCESS_MESSAGE.getMessage());
        resultDTO.setData(t);

        return resultDTO;
    }

}
